home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / windows5 / winsrc17.zip / WINFRACT.C < prev    next >
C/C++ Source or Header  |  1991-11-24  |  57KB  |  1,558 lines

  1. /****************************************************************************
  2.  
  3.  
  4.     PROGRAM: winfract.c
  5.  
  6.     PURPOSE: Windows-specific main-driver code for Fractint for Windows
  7.              (look in MAINFRAC.C for the non-windows-specific code)
  8.  
  9.     Copyright (C) 1990 The Stone Soup Group.  Fractint for Windows 
  10.     may be freely copied and distributed, but may not be sold.
  11.     
  12.     We are, of course, copyrighting the code we wrote to implement
  13.     Fractint-for-Windows, and not the routines we lifted directly
  14.     or indirectly from Microsoft's Windows 3.0 Software Development Kit.
  15.  
  16. ****************************************************************************/
  17.  
  18. #include "windows.h"
  19. #include "winfract.h"
  20. #include "mathtool.h"
  21. #include "fractype.h"
  22. #include "fractint.h"
  23. #include "select.h"
  24. #include <math.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <search.h>
  28. #include <string.h>
  29. #include <time.h>
  30. #include "profile.h"
  31.  
  32. extern LPSTR win_lpCmdLine;
  33.  
  34. HANDLE hInst;
  35.  
  36. HWND hMainWnd, hwnd;                     /* handle to main window */
  37. HWND hWndCopy;                 /* Copy of hWnd */
  38.  
  39. #define PALETTESIZE 256               /* dull-normal VGA                    */
  40. HANDLE hpal;                          /* palette handle                     */
  41. PAINTSTRUCT ps;                       /* paint structure                    */
  42. HDC hDC;                              /* handle to device context           */
  43. HDC hMemoryDC;                        /* handle to memory device context    */
  44. BITMAP Bitmap;                        /* bitmap structure                   */
  45. unsigned IconWidth, IconHeight, IconSize;
  46. HANDLE hIconBitmap;
  47.  
  48. HANDLE  hPal;          /* Handle to the application's logical palette  */
  49. HANDLE  hLogPal;       /* Temporary Handle */
  50. LPLOGPALETTE pLogPal;  /* pointer to tha application's logical palette */
  51. int     iNumColors;    /* Number of colors supported by device           */
  52. int     iRasterCaps;   /* Raster capabilities                           */
  53. int     iPalSize;      /* Size of Physical palette                       */
  54.  
  55. BOOL    win_systempaletteused = FALSE;    /* flag system palette set */
  56. extern int win_syscolorindex[21];
  57. extern DWORD win_syscolorold[21];
  58. extern DWORD win_syscolornew[21];
  59.  
  60. /* MCP 6-16-91 */
  61. extern int pixelshift_per_byte;
  62. extern long pixels_per_bytem1;        /* pixels / byte - 1 (for ANDing) */
  63. extern unsigned char win_andmask[8];
  64. extern unsigned char win_notmask[8];
  65. extern unsigned char win_bitshift[8];
  66.  
  67. extern int CoordBoxOpen;
  68. extern HWND hCoordBox;
  69. extern int TrackingZoom, Zooming, ReSizing;
  70.  
  71. #define EXE_NAME_MAX_SIZE  128
  72.  
  73. BOOL       bHelp = FALSE;      /* Help mode flag; TRUE = "ON"*/
  74. HCURSOR    hHelpCursor;        /* Cursor displayed when in help mode*/
  75. char       szHelpFileName[EXE_NAME_MAX_SIZE+1];    /* Help file name*/
  76.  
  77. void MakeHelpPathName(char*);  /* Function deriving help file path */
  78.  
  79. unsigned char far win_dacbox[256][3];
  80. extern unsigned char dacbox[256][3];
  81. int max_colors;
  82.  
  83. BOOL bTrack = FALSE;                  /* TRUE if user is selecting a region */
  84. BOOL zoomflag = FALSE;                /* TRUE is a zoom-box selected */
  85. RECT Rect;
  86.  
  87. int Shape = SL_BLOCK;            /* shape to use for the selection rectangle */
  88.  
  89. /* pointers to various dialog-box routines */
  90. FARPROC lpProcAbout;
  91. FARPROC lpOpenDlg;
  92. FARPROC lpSelectFractal;
  93. FARPROC lpSelectFracParams;
  94. FARPROC lpSelectImage;
  95. FARPROC lpSelectDoodads;
  96. FARPROC lpSelectCycle;
  97. FARPROC lpSaveAsDlg;
  98. FARPROC lpProcStatus;
  99. FARPROC lpSelect3D;
  100. FARPROC lpSelect3DPlanar;
  101. FARPROC lpSelect3DSpherical;
  102.  
  103. extern int FileFormat;
  104. extern unsigned char readname[], FileName[], FormFileName[];
  105. extern unsigned char FullPathName[], DefPath[];
  106. extern unsigned char LFileName[], LName[];
  107. extern unsigned char DialogTitle[], DefSpec[], DefExt[];
  108.  
  109. HBITMAP hBitmap, oldBitmap, oldoldbitmap;              /* working bitmaps */
  110.  
  111. HANDLE hDibInfo;        /* handle to the Device-independent bitmap */
  112. LPBITMAPINFO pDibInfo;        /* pointer to the DIB info */
  113. HANDLE hpixels;            /* handle to the DIB pixels */
  114. unsigned char huge *pixels;    /* the device-independent bitmap  pixels */
  115. extern int bytes_per_pixelline;    /* pixels/line / pixels/byte */
  116. extern long win_bitmapsize;     /* size of the DIB in bytes */
  117. extern    int    resave_flag;    /* resaving after a timed save */
  118. extern    char overwrite;     /* overwrite on/off */
  119.  
  120. HANDLE hClipboard1, hClipboard2, hClipboard3; /* handles to clipboard info */
  121. LPSTR lpClipboard1, lpClipboard2;            /* pointers to clipboard info */
  122.  
  123. int last_written_y = -2;        /* last line written */
  124. int screen_to_be_cleared = 1;    /* flag that the screen is to be cleared */
  125. int time_to_act = 0;        /* time to take some sort of action? */
  126. int time_to_restart = 0;        /* time to restart?  */
  127. int time_to_reinit = 0;         /* time to reinitialize?  */
  128. int time_to_quit = 0;           /* time to quit? */
  129. int time_to_save = 0;        /* time to save the file? */
  130. int time_to_print = 0;        /* time to print the file? */
  131. int time_to_load = 0;        /* time to load a new file? */
  132. int time_to_cycle = 0;          /* time to begin color-cycling? */
  133.  
  134. int win_3dspherical = 0;          /* spherical 3D? */
  135. int win_display3d, win_overlay3d; /* 3D flags */
  136.  
  137. extern int win_cycledir, win_cyclerand;
  138.  
  139. extern int calc_status;
  140.  
  141. int xdots, ydots, colors, maxiter;
  142. int ytop, ybottom, xleft, xright;
  143. int xposition, yposition, win_xoffset, win_yoffset, xpagesize, ypagesize;
  144. int win_xdots, win_ydots;
  145. extern int fractype;
  146. extern double param[4];
  147. extern double xxmin, xxmax, yymin, yymax, xx3rd, yy3rd;
  148. double jxxmin, jxxmax, jyymin, jyymax, jxx3rd, jyy3rd;
  149. extern int frommandel, bitshift, biomorph;
  150.  
  151. extern char str[255];
  152.  
  153. int cpu, fpu;            /* cpu, fpu flags */
  154.  
  155. extern int win_release;
  156.  
  157. char *win_choices[100];
  158. int win_numchoices, win_choicemade;
  159.  
  160. extern int onthelist[];
  161. extern int CountFractalList;
  162. extern int CurrentFractal;
  163. int MaxFormNameChoices = 80;
  164. char FormNameChoices[80][21];
  165. extern char FormName[30];
  166. extern char    IFSFileName[];    /* IFS code file */
  167. extern char    IFSName[];        /* IFS code item */
  168. double far *temp_array;
  169. HANDLE htemp_array;
  170.  
  171. HANDLE hSaveCursor;             /* the original cursor value */
  172. HANDLE hHourGlass;              /* the hourglass cursor value */
  173.  
  174. /****************************************************************************
  175.  
  176.     FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
  177.  
  178.     PURPOSE: calls initialization function, processes message loop
  179.  
  180. ****************************************************************************/
  181.  
  182. int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
  183. HANDLE hInstance;
  184. HANDLE hPrevInstance;
  185. LPSTR lpCmdLine;
  186. int nCmdShow;
  187. {
  188.     win_lpCmdLine = lpCmdLine;
  189.  
  190.     if (!hPrevInstance)
  191.         if (!InitApplication(hInstance))
  192.             return (FALSE);
  193.  
  194.     if (!InitInstance(hInstance, nCmdShow))
  195.         return (FALSE);
  196.  
  197.     fractint_main();            /* fire up the main Fractint code */
  198.     if(htemp_array) {
  199.         GlobalUnlock(htemp_array);
  200.         GlobalFree(htemp_array);
  201.     }
  202.     DestroyWindow(hWndCopy);    /* stop everything when it returns */
  203.  
  204.     return(0);                  /* we done when 'fractint_main' returns */
  205. }
  206.  
  207. /****************************************************************************
  208.  
  209.     FUNCTION: InitApplication(HANDLE)
  210.  
  211.     PURPOSE: Initializes window data and registers window class
  212.  
  213. ****************************************************************************/
  214.  
  215. BOOL InitApplication(hInstance)
  216. HANDLE hInstance;
  217. {
  218.     WNDCLASS  wc;
  219.  
  220.     wc.style = CS_VREDRAW | CS_HREDRAW | CS_DBLCLKS;
  221.     wc.lpfnWndProc = MainWndProc;
  222.     wc.cbClsExtra = 0;
  223.     wc.cbWndExtra = 0;
  224.     wc.hInstance = hInstance;
  225.     wc.hIcon = NULL;
  226.     wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  227.     wc.hbrBackground = GetStockObject(BLACK_BRUSH);
  228.     wc.lpszMenuName =  "WinFracMenu";
  229.     wc.lpszClassName = "FractintForWindowsV0010";
  230.  
  231.     return(RegisterClass(&wc) && RegisterMathWindows(hInstance));
  232. }
  233.  
  234.  
  235. /****************************************************************************
  236.  
  237.     FUNCTION:  InitInstance(HANDLE, int)
  238.  
  239.     PURPOSE:  Saves instance handle and creates main window
  240.  
  241. ****************************************************************************/
  242. BOOL InitInstance(hInstance, nCmdShow)
  243.     HANDLE          hInstance;
  244.     int             nCmdShow;
  245. {
  246.     DWORD WinFlags;
  247.     int iLoop, jLoop;
  248.     DWORD ThisColor;
  249.  
  250.     float temp;
  251.     char tempname[40];
  252.  
  253.     /* so, what kind of a computer are we on, anyway? */
  254.     WinFlags = GetWinFlags();
  255.     cpu = 88;                             /* determine the CPU type */
  256.     if (WinFlags & WF_CPU186) cpu = 186;
  257.     if (WinFlags & WF_CPU286) cpu = 286;
  258.     if (WinFlags & WF_CPU386) cpu = 386;
  259.     if (WinFlags & WF_CPU486) cpu = 386;
  260.     fpu = 0;                              /* determine the FPU type */
  261.     if (WinFlags & WF_80x87)  fpu = 87;
  262.     if (fpu && (cpu == 386))  fpu = 387;
  263.  
  264.     hInst = hInstance;
  265.  
  266.     temp = win_release / 100.0;
  267.     sprintf(tempname,"Fractint for Windows - Vers %5.2f", temp);
  268.  
  269.     hMainWnd = hwnd = CreateWindow(
  270.         "FractintForWindowsV0010",
  271.         tempname,
  272.         WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
  273.         160, 120,  /* initial locn instead of CW_USEDEFAULT, CW_USEDEFAULT, */
  274.         320, 240,  /* initial size instead of CW_USEDEFAULT, CW_USEDEFAULT, */
  275.         NULL,
  276.         NULL,
  277.         hInstance,
  278.         NULL
  279.     );
  280.  
  281.     if (!hwnd) {  /* ?? can't create the initial window! */
  282.         return (FALSE);
  283.         }
  284.  
  285.     /* This program doesn't run in "real" mode, so shut down right
  286.        now to keep from mucking up Windows */
  287.     if (!((WinFlags & WF_STANDARD) || (WinFlags & WF_ENHANCED))) {
  288.         MessageBox (
  289.             GetFocus(),
  290.             "This program requires Standard\nor 386-Enhanced Mode",
  291.             "Fractint For Windows",
  292.             MB_ICONSTOP | MB_OK);
  293.         return(FALSE);
  294.         }
  295.     
  296.     win_xdots = xdots;
  297.     win_ydots = ydots;
  298.     maxiter = 150;                   /* and a few iterations */
  299.     xposition = yposition = 0;       /* dummy up a few pointers */
  300.     xpagesize = ypagesize = 2000;
  301.     set_win_offset();
  302.  
  303.     /* obtain an hourglass cursor */
  304.     hHourGlass  = LoadCursor(NULL, IDC_WAIT);
  305.     hSaveCursor = LoadCursor(NULL, IDC_ARROW);
  306.  
  307.     SizeWindow(hwnd);
  308.     ShowWindow(hwnd, nCmdShow);
  309.     UpdateWindow(hwnd);
  310.  
  311.     /* let's ensure that we have at lease 40K of free memory */
  312.     {
  313.     HANDLE temphandle;
  314.     if (!(temphandle = GlobalAlloc(GMEM_FIXED,40000L)) ||
  315.         !(htemp_array = GlobalAlloc(GMEM_FIXED, sizeof(double) * 8001))) {
  316.         MessageBox (
  317.             GetFocus(),
  318.             "There isn't enough available\nmemory to run Winfract.",
  319.             "Fractint For Windows",
  320.             MB_ICONSTOP | MB_OK);
  321.         return(FALSE);
  322.         }
  323.         GlobalLock(temphandle);
  324.         GlobalUnlock(temphandle);
  325.         GlobalFree(temphandle);
  326.         temp_array = (double far *)GlobalLock(htemp_array);
  327.     }
  328.  
  329.    MakeHelpPathName(szHelpFileName);
  330.  
  331.     /* so, what kind of a display are we using, anyway? */
  332.     hDC = GetDC(NULL);
  333.     iPalSize    = GetDeviceCaps (hDC, SIZEPALETTE);
  334.     iRasterCaps = GetDeviceCaps (hDC, RASTERCAPS);
  335.     iRasterCaps = (iRasterCaps & RC_PALETTE) ? TRUE : FALSE;
  336.     if (iRasterCaps)
  337.        iNumColors = GetDeviceCaps(hDC, SIZEPALETTE);
  338.     else
  339.        iNumColors = GetDeviceCaps(hDC, NUMCOLORS);
  340.     ReleaseDC(NULL,hDC);
  341.  
  342.     /* fudges for oddball stuff (is there any?) */
  343.     /* also, note that "true color" devices return -1 for NUMCOLORS */
  344.     colors = iNumColors;
  345.     if (colors < 2 || colors > 16) colors = 256;
  346.     if (colors > 2 && colors < 16) colors = 16;
  347.     /* adjust for Windows' 20 reserved palettes in 256-color mode */
  348.     max_colors = 256;
  349.     if (colors == 256  && iNumColors >= 0) max_colors = 236;
  350.  
  351.      /* Allocate enough memory for a logical palette with
  352.       * PALETTESIZE entries and set the size and version fields
  353.       * of the logical palette structure.
  354.       */
  355.      if (!(hLogPal = GlobalAlloc (GMEM_FIXED,
  356.         (sizeof (LOGPALETTE) +
  357.         (sizeof (PALETTEENTRY) * (PALETTESIZE)))))) {
  358.         MessageBox (
  359.             GetFocus(),
  360.             "There isn't enough available\nmemory to run Winfract..",
  361.             "Fractint For Windows",
  362.             MB_ICONSTOP | MB_OK);
  363.         return(FALSE);
  364.           }
  365.     pLogPal = (LPLOGPALETTE)GlobalLock(hLogPal); 
  366.     pLogPal->palVersion    = 0x300;
  367.     pLogPal->palNumEntries = PALETTESIZE;
  368.     /* fill in intensities for all palette entry colors */
  369.     for (iLoop = 0; iLoop < PALETTESIZE; iLoop++) {
  370.         pLogPal->palPalEntry[iLoop].peRed   = iLoop;
  371.         pLogPal->palPalEntry[iLoop].peGreen = 0;
  372.         pLogPal->palPalEntry[iLoop].peBlue  = 0;
  373.         pLogPal->palPalEntry[iLoop].peFlags = PC_EXPLICIT;
  374.         }
  375.     /* flip the ugly red color #1 with the pretty blue color #4 */
  376.     if (iNumColors < 0 || iNumColors > 4) {
  377.         pLogPal->palPalEntry[1].peRed = 4;
  378.         pLogPal->palPalEntry[4].peRed = 1;
  379.         }
  380.     /*  create a logical color palette according the information
  381.         in the LOGPALETTE structure. */
  382.     hPal = CreatePalette ((LPLOGPALETTE) pLogPal) ;
  383.     hDC = GetDC(GetFocus());
  384.     SetMapMode(hDC,MM_TEXT);
  385.     SelectPalette (hDC, hPal, 1);
  386.     RealizePalette(hDC);
  387.     /* get the "real" colors */
  388.     jLoop = iNumColors;
  389.     if (jLoop < 0) jLoop = -1;
  390.     for (iLoop = 0; iLoop < PALETTESIZE; iLoop++){
  391.         if (++jLoop >= iNumColors)
  392.             if (iNumColors > 0)
  393.                 jLoop = 0;
  394.         ThisColor = GetNearestColor (hDC, PALETTEINDEX (jLoop) );
  395.         win_dacbox[iLoop][0] = dacbox[iLoop][0] =
  396.             ((BYTE)GetRValue (ThisColor)) >> 2;
  397.         win_dacbox[iLoop][1] = dacbox[iLoop][1] =
  398.             ((BYTE)GetGValue (ThisColor)) >> 2;
  399.         win_dacbox[iLoop][2] = dacbox[iLoop][2] =
  400.             ((BYTE)GetBValue (ThisColor)) >> 2;
  401.         }
  402.     ReleaseDC(GetFocus(),hDC);
  403.  
  404.     /* allocate a device-independent bitmap header */
  405.     if (!(hDibInfo = GlobalAlloc(GMEM_FIXED,
  406.         sizeof(BITMAPINFOHEADER)+256*sizeof(PALETTEENTRY)))) {
  407.         MessageBox (
  408.             GetFocus(),
  409.             "There isn't enough available\nmemory to run Winfract...",
  410.             "Fractint For Windows",
  411.             MB_ICONSTOP | MB_OK);
  412.         return(FALSE);
  413.         }
  414.     pDibInfo = (LPBITMAPINFO)GlobalLock(hDibInfo);
  415.     /* fill in the header */
  416.     pDibInfo->bmiHeader.biSize  = (long)sizeof(BITMAPINFOHEADER);
  417.     pDibInfo->bmiHeader.biWidth  = win_xdots;
  418.     pDibInfo->bmiHeader.biHeight = win_ydots;
  419.     pDibInfo->bmiHeader.biSizeImage = (DWORD)win_xdots * win_ydots;
  420.     pDibInfo->bmiHeader.biPlanes = 1;
  421.     pDibInfo->bmiHeader.biBitCount = 8;
  422.     pDibInfo->bmiHeader.biCompression = BI_RGB;
  423.     pDibInfo->bmiHeader.biXPelsPerMeter = 0L;
  424.     pDibInfo->bmiHeader.biYPelsPerMeter = 0L;
  425.     pDibInfo->bmiHeader.biClrUsed = 0L;
  426.     pDibInfo->bmiHeader.biClrImportant = 0L;
  427.     default_dib_palette();
  428.  
  429.     IconWidth = GetSystemMetrics(SM_CXICON);
  430.     IconHeight = GetSystemMetrics(SM_CYICON);
  431.     IconSize = (IconWidth * IconHeight) >> pixelshift_per_byte;
  432.     hIconBitmap = GlobalAlloc(GMEM_MOVEABLE, IconSize);
  433.  
  434.     /* allocate and lock a pixel array for the initial bitmap */
  435.     hpixels = (HANDLE) 0;
  436.     pixels = (char huge *) NULL;
  437.     if (hIconBitmap && clear_screen(0))
  438.         return(TRUE);
  439.  
  440.     MessageBox (
  441.         GetFocus(),
  442.         "There isn't enough available\nmemory to run Winfract....",
  443.         "Fractint For Windows",
  444.          MB_ICONSTOP | MB_OK);
  445.  
  446.     return (FALSE);
  447.  
  448. }
  449.  
  450. /****************************************************************************
  451.  
  452.     FUNCTION: MainWndProc(HWND, unsigned, WORD, LONG)
  453.  
  454.     PURPOSE:  Processes messages
  455.  
  456. ****************************************************************************/
  457.  
  458. void lmemcpy(  char huge *to,  char huge *from, long len)
  459. {
  460. long i;
  461.  
  462. for (i = 0; i < len; i++)
  463.   to[i] = from[i];
  464. }
  465.  
  466. long FAR PASCAL MainWndProc(hWnd, message, wParam, lParam)
  467. HWND hWnd;                /* handle to main window */
  468. unsigned message;
  469. WORD wParam;
  470. LONG lParam;
  471. {
  472.  
  473.     RECT tempRect;
  474.  
  475.     int Return;
  476.     int i, fchoice;
  477.  
  478.     switch (message) {
  479.  
  480.         case WM_INITMENU:
  481.            if (!iRasterCaps || iNumColors < 16) {
  482.                EnableMenuItem(GetMenu(hWnd), IDM_CYCLE, MF_DISABLED);
  483.                EnableMenuItem(GetMenu(hWnd), IDM_CYCLE, MF_GRAYED);
  484.                }
  485.            return (TRUE);
  486.  
  487.        case WM_KEYDOWN:
  488.            switch (wParam) {
  489.                case VK_F1:
  490.                /* F1, shifted F1 bring up the Help Index */
  491.                    WinHelp(hWnd,szHelpFileName,HELP_INDEX,0L);
  492.                    break;
  493.                
  494.                case VK_ESCAPE:
  495.                   if(Zooming)
  496.                      CancelZoom();
  497.                   break;
  498.                case VK_SPACE:
  499.                /* Space/etc.. toggles Color-cycling parameters */
  500.                    if (time_to_cycle == 1)
  501.                        time_to_cycle = 0;
  502.                    else
  503.                        if (win_oktocycle())
  504.                             time_to_cycle = 1;
  505.                    break;
  506.                case VK_RIGHT:
  507.                case VK_ADD: 
  508.                    if (win_oktocycle()) {
  509.                        time_to_cycle = 1;
  510.                        win_cycledir = -1;
  511.                        }
  512.                    break;
  513.                case VK_LEFT:
  514.                case VK_SUBTRACT: 
  515.                    if (win_oktocycle()) {
  516.                        time_to_cycle = 1;
  517.                        win_cycledir = 1;
  518.                        }
  519.                    break;
  520.                case VK_RETURN:
  521.                    if(Zooming)
  522.                       ExecuteZoom();
  523.                    else if (win_oktocycle()) {
  524.                        time_to_cycle = 1;
  525.                        win_cyclerand = 2;
  526.                        }
  527.                    break;
  528.                }
  529.            break;
  530.         case WM_LBUTTONDBLCLK:
  531.             if(Zooming)
  532.                ExecuteZoom();
  533.             break;
  534.  
  535.         case WM_LBUTTONDOWN:           /* message: left mouse button pressed */
  536.  
  537.             /* Start selection of region */
  538.  
  539.             if(!Zooming) {
  540.                bTrack = TRUE;
  541.                SetRectEmpty(&Rect);
  542.                StartSelection(hWnd, MAKEPOINT(lParam), &Rect,
  543.                    (wParam & MK_SHIFT) ? (SL_EXTEND | Shape) : Shape);
  544.             }
  545.             else
  546.                StartZoomTracking(lParam);
  547.             break;
  548.  
  549.         case WM_MOUSEMOVE:                        /* message: mouse movement */
  550.  
  551.             /* Update the selection region */
  552.  
  553.             if (bTrack)
  554.                 UpdateSelection(hWnd, MAKEPOINT(lParam), &Rect, Shape);
  555.             if(CoordBoxOpen)
  556.                 UpdateCoordBox(lParam);
  557.             if(TrackingZoom)
  558.                TrackZoom(lParam);
  559.             break;
  560.  
  561.         case WM_LBUTTONUP:            /* message: left mouse button released */
  562.  
  563.             if (bTrack) {
  564.  
  565.                /* End the selection */
  566.  
  567.                EndSelection(MAKEPOINT(lParam), &Rect);
  568.  
  569.                ClearSelection(hWnd, &Rect, Shape);
  570.                
  571.                if (abs(Rect.bottom - Rect.top ) > 5 &&
  572.                    abs(Rect.right  - Rect.left) > 5) {
  573.                    
  574.                    float win_aspect, zoom_aspect, rel_aspect;
  575.  
  576.                    ytop    = Rect.top;
  577.                    ybottom = Rect.bottom;
  578.                    xleft   = Rect.left;
  579.                    xright  = Rect.right;
  580.                    xleft    = xleft   + win_xoffset;
  581.                    ytop     = ytop    + win_yoffset;
  582.                    xright   = xright  + win_xoffset;
  583.                    ybottom  = ybottom + win_yoffset;
  584.                    
  585.                    /* adjust the zoom-box for aspect ratio */
  586.                    win_aspect = (float)ydots/(float)xdots;
  587.                    zoom_aspect = (float)(ybottom-ytop+1)/(float)(xright-xleft+1);
  588.                    rel_aspect = win_aspect/zoom_aspect;
  589.                    
  590.                    if (rel_aspect > 1.0 && rel_aspect < 1.50) {
  591.                        ybottom = ytop + ((xright-xleft+1)*win_aspect) - 1;
  592.                        if (ybottom >= ydots) ybottom = ydots-1;
  593.                        }
  594.                    if (rel_aspect < 1.0 && rel_aspect > 0.66) {
  595.                        xright = xleft + ((ybottom-ytop+1)/win_aspect) - 1;
  596.                        if (xright >= xdots) xright = xdots-1;
  597.                        }
  598.                    
  599.                    zoomflag = TRUE;
  600.                    time_to_restart = 1;
  601.                    time_to_cycle = 0;
  602.                    calc_status = 0;
  603.                    }
  604.  
  605.                bTrack = FALSE;
  606.  
  607.             }
  608.             if(TrackingZoom)
  609.                EndZoom(lParam);
  610.             break;
  611.  
  612.         case WM_RBUTTONUP:
  613.             {
  614.             int xx, yy;
  615.             xx = LOWORD(lParam);
  616.             yy = HIWORD(lParam);
  617.             xx += win_xoffset;
  618.             yy += win_yoffset;
  619.             if (xx >= xdots || yy >= ydots) 
  620.                 break;
  621.             if (fractalspecific[fractype].tojulia != NOFRACTAL
  622.                 && param[0] == 0.0 && param[1] == 0.0) {
  623.                 /* switch to corresponding Julia set */
  624.                 fractype = fractalspecific[fractype].tojulia;
  625.                 param[0] = xxmin + (xxmax - xxmin) * xx / xdots;
  626.                 param[1] = yymax - (yymax - yymin) * yy / ydots;
  627.                 jxxmin = xxmin; jxxmax = xxmax;
  628.                 jyymax = yymax; jyymin = yymin;
  629.                 jxx3rd = xx3rd; jyy3rd = yy3rd;
  630.                 frommandel = 1;
  631.                 xxmin = fractalspecific[fractype].xmin;
  632.                 xxmax = fractalspecific[fractype].xmax;
  633.                 yymin = fractalspecific[fractype].ymin;
  634.                 yymax = fractalspecific[fractype].ymax;
  635.                 xx3rd = xxmin;
  636.                 yy3rd = yymin;
  637.                 if(biomorph != -1 && bitshift != 29) {
  638.                    xxmin *= 3.0;
  639.                    xxmax *= 3.0;
  640.                    yymin *= 3.0;
  641.                    yymax *= 3.0;
  642.                    xx3rd *= 3.0;
  643.                    yy3rd *= 3.0;
  644.                    }
  645.                 calc_status = 0;
  646.                 }
  647.             else if (fractalspecific[fractype].tomandel != NOFRACTAL) {
  648.                 /* switch to corresponding Mandel set */
  649.                 fractype = fractalspecific[fractype].tomandel;
  650.                 if (frommandel) {
  651.                     xxmin = jxxmin;  xxmax = jxxmax;
  652.                     yymin = jyymin;  yymax = jyymax;
  653.                     xx3rd = jxx3rd;  yy3rd = jyy3rd;
  654.                     }
  655.                 else {
  656.                     double ccreal,ccimag;
  657.                     ccreal = (fractalspecific[fractype].xmax - fractalspecific[fractype].xmin) / 2;
  658.                     ccimag = (fractalspecific[fractype].ymax - fractalspecific[fractype].ymin) / 2;
  659.                     xxmin = xx3rd = param[0] - ccreal;
  660.                     xxmax = param[0] + ccreal;
  661.                     yymin = yy3rd = param[1] - ccimag;
  662.                     yymax = param[1] + ccimag;
  663.                     }
  664.                 frommandel = 0;
  665.                 param[0] = 0;
  666.                 param[1] = 0;
  667.                 calc_status = 0;
  668.                 }
  669.             else {
  670.                 buzzer(2); /* can't switch */
  671.                 break;
  672.                 }
  673.  
  674.             ytop    = 0;
  675.             ybottom = ydots-1;
  676.             xleft   = 0;
  677.             xright  = xdots-1;
  678.  
  679.             time_to_restart  = 1;
  680.             time_to_cycle = 0;
  681.             calc_status = 0;
  682.             }
  683.             break;
  684.  
  685.         case WM_CREATE:
  686.  
  687.             /* the scroll bars are hard-coded to 100 possible values */
  688.             xposition = yposition = 0;      /* initial scroll-bar positions */
  689.             SetScrollRange(hWnd,SB_HORZ,0,100,FALSE);
  690.             SetScrollRange(hWnd,SB_VERT,0,100,FALSE);
  691.             SetScrollPos(hWnd,SB_HORZ,xposition,TRUE);
  692.             SetScrollPos(hWnd,SB_VERT,yposition,TRUE);
  693.             InitializeParameters(hWnd);
  694.             break;
  695.  
  696.         case WM_SIZE:
  697.             xpagesize = LOWORD(lParam);        /* remember the window size */
  698.             ypagesize = HIWORD(lParam);
  699.         set_win_offset();
  700.             if(!ReSizing && !IsIconic(hWnd))
  701.            ReSizeWindow(hWnd);
  702.             break;
  703.  
  704.         case WM_MOVE:
  705.             SaveWindowPosition(hWnd, WinfractPosStr);
  706.             break;
  707.  
  708.         case WM_HSCROLL:
  709.             switch (wParam) {
  710.                case SB_LINEDOWN:       xposition += 1; break;
  711.                case SB_LINEUP:         xposition -= 1; break;
  712.                case SB_PAGEDOWN:       xposition += 10; break;
  713.                case SB_PAGEUP:         xposition -= 10; break;
  714.                case SB_THUMBPOSITION:  xposition = LOWORD(lParam);
  715.                default:                break;
  716.                }
  717.             if (xposition > 100) xposition = 100;
  718.             if (xposition <     0) xposition = 0;
  719.             if (xposition != GetScrollPos(hWnd,SB_HORZ)) {
  720.                SetScrollPos(hWnd,SB_HORZ,xposition,TRUE);
  721.                InvalidateRect(hWnd,NULL,TRUE);
  722.                }
  723.             set_win_offset();
  724.            break;
  725.         case WM_VSCROLL:
  726.             switch (wParam) {
  727.                case SB_LINEDOWN:       yposition += 1; break;
  728.                case SB_LINEUP:         yposition -= 1; break;
  729.                case SB_PAGEDOWN:       yposition += 10; break;
  730.                case SB_PAGEUP:         yposition -= 10; break;
  731.                case SB_THUMBPOSITION:  yposition = LOWORD(lParam);
  732.                default:                break;
  733.                }
  734.             if (yposition > 100) yposition = 100;
  735.             if (yposition <     0) yposition = 0;
  736.             if (yposition != GetScrollPos(hWnd,SB_VERT)) {
  737.                SetScrollPos(hWnd,SB_VERT,yposition,TRUE);
  738.                InvalidateRect(hWnd,NULL,TRUE);
  739.                }
  740.             set_win_offset();
  741.             break;
  742.         case WM_CLOSE:
  743.             goto GlobalExit;
  744.  
  745.         case WM_COMMAND:
  746.             switch (wParam) {
  747.                 case IDM_COORD:
  748.                     CoordinateBox(hWnd);
  749.                     break;
  750.                 case IDM_ABOUT:
  751.                     lpProcAbout = MakeProcInstance(About, hInst);
  752.                     DialogBox(hInst, "AboutBox", hWnd, lpProcAbout);
  753.                     FreeProcInstance(lpProcAbout);
  754.                     break;
  755.  
  756.                case IDM_HELP_INDEX:
  757.                    WinHelp(hWnd,szHelpFileName,HELP_INDEX,0L);
  758.                    break;
  759.  
  760.                case IDM_HELP_KEYBOARD:
  761.            WinHelp(hWnd,szHelpFileName,HELP_KEY,(DWORD)(LPSTR)"keys");
  762.                    break;
  763.  
  764.                case IDM_HELP_HELP:
  765.            WinHelp(hWnd,"WINHELP.HLP",HELP_INDEX,0L);
  766.                    break;
  767.                    
  768.                 case IDM_COPY:
  769.                    /* allocate the memory for the BITMAPINFO structure 
  770.                       (followed by the bitmap bits) */
  771.                    if (!(hClipboard1 = GlobalAlloc(GMEM_FIXED,
  772.                    sizeof(BITMAPINFOHEADER)+colors*sizeof(PALETTEENTRY)
  773.                    + win_bitmapsize))) {
  774.                         cant_clip();
  775.                         return(TRUE);
  776.                         }
  777.                     if (!(lpClipboard1 =
  778.                         (LPSTR) GlobalLock(hClipboard1))) {
  779.                         GlobalFree(hClipboard1);
  780.                         cant_clip();
  781.                         return(TRUE);
  782.                         }
  783.                     rgb_dib_palette();
  784.                     lmemcpy((char huge *)lpClipboard1, (char huge *)pDibInfo,
  785.                         sizeof(BITMAPINFOHEADER)+colors*sizeof(RGBQUAD)
  786.                         );
  787.                     lpClipboard1 += 
  788.                         (sizeof(BITMAPINFOHEADER))+
  789.                         (colors*sizeof(RGBQUAD));
  790.                     lmemcpy((char huge *)lpClipboard1, (char huge *)pixels,
  791.                         win_bitmapsize);
  792.  
  793.                     GlobalUnlock(hClipboard1);
  794.  
  795.                    /* allocate the memory for the palette info */
  796.                    if (!lpClipboard2) {
  797.                        if (!(hClipboard2 = GlobalAlloc (GMEM_FIXED,
  798.                            (sizeof (LOGPALETTE) +
  799.                            (sizeof (PALETTEENTRY) * (PALETTESIZE)))))) {
  800.                             GlobalFree(hClipboard1);
  801.                             cant_clip();
  802.                             return(TRUE);
  803.                             }
  804.                         if (!(lpClipboard2 = 
  805.                             (LPSTR) GlobalLock(hClipboard2))) {
  806.                             GlobalFree(hClipboard1);
  807.                             GlobalFree(hClipboard2);
  808.                             cant_clip();
  809.                             return(TRUE);
  810.                             }
  811.                        }
  812.                    /* fill in the palette info */
  813.                    lpClipboard2[0] = 0;
  814.                    lpClipboard2[1] = 3;
  815.                    lpClipboard2[2] = 0;
  816.                    lpClipboard2[3] = 1;
  817.                    lmemcpy((char huge *)&lpClipboard2[4],
  818.                         (char huge *)&pDibInfo->bmiColors[0],
  819.                         PALETTESIZE*sizeof(RGBQUAD)
  820.                         );
  821.                    hClipboard3 = CreatePalette ((LPLOGPALETTE) lpClipboard2);
  822.  
  823.                     hDC = GetDC(hWnd);
  824.                     hBitmap = CreateDIBitmap(hDC, &pDibInfo->bmiHeader,
  825.                               CBM_INIT, (LPSTR)pixels, pDibInfo,
  826.                               DIB_RGB_COLORS);
  827.                     ReleaseDC(hWnd, hDC);
  828.  
  829.                     if (OpenClipboard(hWnd)) {
  830.                         EmptyClipboard();
  831.                         SetClipboardData(CF_PALETTE, hClipboard3);
  832.                         SetClipboardData(CF_DIB, hClipboard1);
  833.                         if(hBitmap)
  834.                           SetClipboardData(CF_BITMAP, hBitmap);
  835.                         CloseClipboard();
  836.                         }
  837.  
  838.                     default_dib_palette();
  839.  
  840.                     break;
  841.  
  842.                 case IDM_NEW:
  843.                 case IDM_OPEN:
  844.                 case IDM_3D:
  845.                 case IDM_3DOVER:
  846.                     win_display3d = 0;
  847.                     win_overlay3d = 0;
  848.                     /* Call OpenDlg() to get the filename */
  849.                     strcpy(DialogTitle,"Select a File to Open");
  850.                     strcpy(FileName, readname);
  851.                     strcpy(DefSpec,"*.gif");
  852.                     strcpy(DefExt,".gif");
  853.                     lpOpenDlg = MakeProcInstance((FARPROC) OpenDlg, hInst);
  854.                     Return = DialogBox(hInst, "Open", hWnd, lpOpenDlg);
  855.                     FreeProcInstance(lpOpenDlg);
  856.                     if (Return && (wParam == IDM_3D || wParam == IDM_3DOVER)) {
  857.                         lpSelect3D = MakeProcInstance(
  858.                             (FARPROC) Select3D, hInst);
  859.                         Return = DialogBox(hInst, "Select3D",
  860.                              hWnd, lpSelect3D);
  861.                         FreeProcInstance(lpSelect3D);
  862.                         if (Return && !win_3dspherical) {
  863.                             lpSelect3DPlanar = MakeProcInstance(
  864.                                 (FARPROC) Select3DPlanar, hInst);
  865.                             Return = DialogBox(hInst, "Select3DPlanar",
  866.                                  hWnd, lpSelect3DPlanar);
  867.                             FreeProcInstance(lpSelect3DPlanar);
  868.                             }
  869.                         if (Return && win_3dspherical) {
  870.                             lpSelect3DSpherical = MakeProcInstance(
  871.                                 (FARPROC) Select3DSpherical, hInst);
  872.                             Return = DialogBox(hInst, "Select3DSpherical",
  873.                                  hWnd, lpSelect3DSpherical);
  874.                             FreeProcInstance(lpSelect3DSpherical);
  875.                             }
  876.                         }
  877.                     if (Return) {
  878.                         strcpy(readname,FileName);
  879.                         time_to_load = 1;
  880.                         time_to_cycle = 0;
  881.                         if (wParam == IDM_3D || wParam == IDM_3DOVER)
  882.                             win_display3d = 1;
  883.                         if (wParam == IDM_3DOVER)
  884.                             win_overlay3d = 1;
  885.                         }
  886.                     break;
  887.  
  888.                 case IDM_MAPIN:
  889.                 case IDM_MAPOUT:
  890.                     /* Call OpenDlg() to get the filename */
  891.                     strcpy(DialogTitle,"Select a File to Open");
  892.                     strcpy(FileName, "default");
  893.                     if (wParam == IDM_MAPOUT)
  894.                         strcpy(FileName, "mymap");
  895.                     strcpy(DefSpec,"*.map");
  896.                     strcpy(DefExt,".map");
  897.                     lpOpenDlg = MakeProcInstance((FARPROC) OpenDlg, hInst);
  898.                     Return = DialogBox(hInst, "Open", hWnd, lpOpenDlg);
  899.                     FreeProcInstance(lpOpenDlg);
  900.                     if (Return && wParam == IDM_MAPIN) {
  901.                         ValidateLuts(FileName);
  902.                         spindac(0,1);
  903.                         }
  904.                     if (Return && wParam == IDM_MAPOUT) {
  905.                         FILE *dacfile;
  906.             dacfile = fopen(FileName,"w");
  907.             if (dacfile == NULL) {
  908.                 break;
  909.                 }
  910.             fprintf(dacfile,"  0   0   0\n");
  911.             for (i = 1; i < 256; i++)
  912.                 fprintf(dacfile, "%3d %3d %3d\n",
  913.                 dacbox[i][0] << 2,
  914.                 dacbox[i][1] << 2,
  915.                 dacbox[i][2] << 2);
  916.             fclose(dacfile);
  917.                         }
  918.                     break;
  919.  
  920.                 case IDM_SAVE:
  921.                 case IDM_SAVEAS:
  922.                     /* Call the SaveAsDlg() function to get the new filename */
  923.                     strcpy(DialogTitle,"Select a File to Save");
  924.                     strcpy(FileName, readname);
  925.  
  926.                     /* MCP 10-27-91, Moved to DIALOG.C
  927.                     strcpy(DefSpec,"*.gif");
  928.                     strcpy(DefExt,".gif");
  929.                     */
  930.  
  931.                     lpSaveAsDlg = MakeProcInstance(SaveAsDlg, hInst);
  932.                     DialogBox(hInst, "SaveAs", hWnd, lpSaveAsDlg);
  933.                     FreeProcInstance(lpSaveAsDlg);
  934.                     if (time_to_save)
  935.                     {
  936.                        wsprintf(StatusTitle, "Saving:  %s", (LPSTR)FullPathName);
  937.                        OpenStatusBox(hWnd, hInst);
  938.                        resave_flag = overwrite = 1;
  939.                     }
  940.                     break;
  941.  
  942.         case IDM_SIZING:
  943.             WindowSizing(hWnd);
  944.             break;
  945.  
  946.                 case IDM_PRINT:
  947.                     time_to_print = 1;
  948.                     time_to_cycle = 0;
  949.                     break;
  950.  
  951.                 case IDM_FORMULA:
  952.                     strcpy(DialogTitle,"Select a Fractal Formula");
  953.                     win_numchoices = CountFractalList;
  954.                     win_choicemade = 0;
  955.                     CurrentFractal = fractype;
  956.                     for (i = 0; i < win_numchoices; i++) {
  957.                         win_choices[i] = fractalspecific[onthelist[i]].name;
  958.                         if (onthelist[i] == fractype ||
  959.                             fractalspecific[onthelist[i]].tofloat == fractype)
  960.                             win_choicemade = i;
  961.                         }
  962.                     lpSelectFractal = MakeProcInstance(SelectFractal, hInst);
  963.                     Return = DialogBox(hInst, "SelectFractal",
  964.                         hWnd, lpSelectFractal);
  965.                     FreeProcInstance(lpSelectFractal);
  966.                     fchoice = win_choicemade;
  967.                     if (Return && (onthelist[fchoice] == IFS ||
  968.                         onthelist[fchoice] == IFS3D)) {
  969.                         strcpy(DialogTitle,"Select an IFS Filename");
  970.                         strcpy(FileName, IFSFileName);
  971.                         strcpy(DefSpec,"*.ifs");
  972.                         strcpy(DefExt,".ifs");
  973.                         lpOpenDlg = MakeProcInstance((FARPROC) OpenDlg, hInst);
  974.                         Return = DialogBox(hInst, "Open", hWnd, lpOpenDlg);
  975.                         FreeProcInstance(lpOpenDlg);
  976.                         if (Return) {
  977.                             strcpy(IFSFileName, FileName);
  978.                             strcpy(FormFileName, FileName);
  979.                             get_formula_names();
  980.                             strcpy(DialogTitle,"Select an IFS type");
  981.                             win_choicemade = 0;
  982.                             lpSelectFractal = MakeProcInstance(SelectFractal, hInst);
  983.                             Return = DialogBox(hInst, "SelectFractal",
  984.                                 hWnd, lpSelectFractal);
  985.                             FreeProcInstance(lpSelectFractal);
  986.                             if (Return) {
  987.                                 strcpy(IFSName, win_choices[win_choicemade]);
  988.                                 Return = ! ifsload();
  989.                                 }
  990.                             }
  991.                         }
  992.                     if (Return && (onthelist[fchoice] == FORMULA || 
  993.                         onthelist[fchoice] == FFORMULA)) {
  994.                         /* obtain the formula filename */
  995.                         strcpy(DialogTitle,"Select a Formula File");
  996.                         strcpy(FileName, FormFileName);
  997.                         strcpy(DefSpec,"*.frm");
  998.                         strcpy(DefExt,".frm");
  999.                         lpOpenDlg = MakeProcInstance((FARPROC) OpenDlg, hInst);
  1000.                         Return = DialogBox(hInst, "Open", hWnd, lpOpenDlg);
  1001.                         FreeProcInstance(lpOpenDlg);
  1002.                         if (Return) {
  1003.                             strcpy(FormFileName, FileName);
  1004.                             get_formula_names();
  1005.                             strcpy(DialogTitle,"Select a Formula");
  1006.                             win_choicemade = 0;
  1007.                             lpSelectFractal = MakeProcInstance(SelectFractal, hInst);
  1008.                             Return = DialogBox(hInst, "SelectFractal",
  1009.                                 hWnd, lpSelectFractal);
  1010.                             FreeProcInstance(lpSelectFractal);
  1011.                             if (Return) 
  1012.                                 Return = parse_formula_names();
  1013.                             }
  1014.                         }
  1015.                     if (Return && (onthelist[fchoice] == LSYSTEM)) {
  1016.                         /* obtain the lsystem formula filename */
  1017.                         strcpy(DialogTitle,"Select an Lsystem File");
  1018.                         strcpy(FileName, LFileName);
  1019.                         strcpy(DefSpec,"*.l");
  1020.                         strcpy(DefExt,".l");
  1021.                         lpOpenDlg = MakeProcInstance((FARPROC) OpenDlg, hInst);
  1022.                         Return = DialogBox(hInst, "Open", hWnd, lpOpenDlg);
  1023.                         FreeProcInstance(lpOpenDlg);
  1024.                         if (Return) {
  1025.                             strcpy(LFileName, FileName);
  1026.                             get_lsys_name();
  1027.                             strcpy(DialogTitle,"Select a Formula");
  1028.                             win_choicemade = 0;
  1029.                             lpSelectFractal = MakeProcInstance(SelectFractal, hInst);
  1030.                             Return = DialogBox(hInst, "SelectFractal",
  1031.                                 hWnd, lpSelectFractal);
  1032.                             FreeProcInstance(lpSelectFractal);
  1033.                             if (Return) {
  1034.                                 strcpy(LName, win_choices[win_choicemade]);
  1035.                                 Return = !LLoad();
  1036.                                 }
  1037.                             }
  1038.                         }
  1039.                     if (Return) {
  1040.                         CurrentFractal = onthelist[fchoice];
  1041.                         lpSelectFracParams = MakeProcInstance(SelectFracParams,
  1042.                             hInst);
  1043.                         Return = DialogBox(hInst, "SelectFracParams",
  1044.                             hWnd, lpSelectFracParams);
  1045.                         FreeProcInstance(lpSelectFracParams);
  1046.                         }
  1047.                     if (Return) {
  1048.             restoredac();
  1049.                         time_to_reinit = 1;
  1050.                         time_to_cycle = 0;
  1051.                         calc_status = 0;
  1052.                         }
  1053.                     break;
  1054.  
  1055.                 case IDM_IMAGE:
  1056.             lpSelectImage = MakeProcInstance(SelectImage, hInst);
  1057.             Return = DialogBox(hInst, "SelectImage",
  1058.                 hWnd, lpSelectImage);
  1059.             FreeProcInstance(lpSelectImage);
  1060.             if (Return) {
  1061.                 restoredac();
  1062.                 time_to_restart = 1;
  1063.                                 time_to_cycle = 0;
  1064.                                 calc_status = 0;
  1065.                 }
  1066.             ReSizeWindow(hWnd);
  1067.                         break;
  1068.  
  1069.                 case IDM_DOODADS:
  1070.             lpSelectDoodads = MakeProcInstance(SelectDoodads, hInst);
  1071.             Return = DialogBox(hInst, "SelectDoodads",
  1072.                 hWnd, lpSelectDoodads);
  1073.             FreeProcInstance(lpSelectDoodads);
  1074.             if (Return) {
  1075.                 restoredac();
  1076.                 time_to_restart = 1;
  1077.                                 time_to_cycle = 0;
  1078.                                 calc_status = 0;
  1079.                 }
  1080.                         break;
  1081.  
  1082.                 case IDM_CYCLE:
  1083.                     if (!win_oktocycle())
  1084.                         break;
  1085.                     lpSelectCycle = MakeProcInstance(SelectCycle, hInst);
  1086.                     Return = DialogBox(hInst, "SelectCycle",
  1087.                     hWnd, lpSelectCycle);
  1088.                     FreeProcInstance(lpSelectCycle);
  1089.                     break;
  1090.  
  1091.                 case IDM_MATH_TOOLS:
  1092.                     MathToolBox(hWnd);
  1093.                     break;
  1094.  
  1095.                 case IDM_ZOOM:
  1096.                     ZoomBar(hWnd);
  1097.                     break;
  1098.  
  1099.                 case IDS_STATUS:
  1100.                     lpProcStatus = MakeProcInstance(Status, hInst);
  1101.                     DialogBox(hInst, "ShowStatus", hWnd, lpProcStatus);
  1102.                     FreeProcInstance(lpProcStatus);
  1103.                     break;
  1104.  
  1105.                 GlobalExit:
  1106.                 case IDM_EXIT:
  1107.                     time_to_quit = 1;
  1108.                     time_to_cycle = 0;
  1109.                     ValidateRect(hWnd, NULL);
  1110.                     hWndCopy = hWnd;
  1111.                     /* the main routine will actually call 'DestroyWindow()' */
  1112.                     break;
  1113.  
  1114.                 case IDC_EDIT:
  1115.                     if (HIWORD (lParam) == EN_ERRSPACE) {
  1116.                         MessageBox (
  1117.                               GetFocus ()
  1118.                             , "Out of memory."
  1119.                             , "Fractint For Windows"
  1120.                             , MB_ICONSTOP | MB_OK
  1121.                         );
  1122.                     }
  1123.                     break;
  1124.  
  1125.             } 
  1126.             break;
  1127.  
  1128.         case WM_PAINT:
  1129.             if (screen_to_be_cleared && last_written_y < 0) {
  1130.                  /* an empty window */
  1131.                  screen_to_be_cleared = 0;
  1132.                  GetUpdateRect(hWnd, &tempRect, TRUE);
  1133.                  hDC = BeginPaint(hWnd,&ps);
  1134.                  if (last_written_y == -2)
  1135.                      last_written_y = -1;
  1136.                  else
  1137.                      BitBlt(hDC, 0, 0, xdots, ydots,
  1138.                          NULL, 0, 0, BLACKNESS);
  1139.                  ValidateRect(hWnd, &tempRect);
  1140.                  EndPaint(hWnd,&ps);
  1141.                  break;
  1142.                  }
  1143.             if(IsIconic(hWnd)) {
  1144.                int x, y;
  1145.                LPSTR icon;
  1146.                long lx, ly, dlx, dly;
  1147.                DWORD tSize, tWidth, tHeight;
  1148.  
  1149.                if((icon = GlobalLock(hIconBitmap)) == NULL)
  1150.                   break;
  1151.  
  1152.                dlx = ((long)xdots << 8) / IconWidth;
  1153.                dly = ((long)ydots << 8) / IconHeight;
  1154.                for(ly = y = 0; y < IconHeight; y++, ly += dly)
  1155.                {
  1156.                   for(lx = x = 0; x < IconWidth; x++, lx += dlx)
  1157.                   {
  1158.                      unsigned ix, iy;
  1159.                      unsigned char color;
  1160.  
  1161.                      ix = lx >> 8;
  1162.                      iy = ly >> 8;
  1163.                      color = getcolor(ix, iy);
  1164.  
  1165.                      ix = IconWidth - y - 1;
  1166.                      ix = (ix * IconWidth) + x;
  1167.                      iy = ix & pixels_per_bytem1;
  1168.                      ix = ix >> pixelshift_per_byte;
  1169.                      icon[ix] = (icon[ix] & win_notmask[iy]) +
  1170.                                (color << win_bitshift[iy]);
  1171.                   }
  1172.                }
  1173.  
  1174.                hDC = BeginPaint(hWnd, &ps);
  1175.  
  1176.                SelectPalette (hDC, hPal, 0);
  1177.                RealizePalette(hDC);
  1178.  
  1179.                tSize   = pDibInfo->bmiHeader.biSizeImage;
  1180.                tHeight = pDibInfo->bmiHeader.biHeight;
  1181.                tWidth  = pDibInfo->bmiHeader.biWidth;
  1182.  
  1183.                pDibInfo->bmiHeader.biSizeImage = IconSize;
  1184.                pDibInfo->bmiHeader.biHeight    = IconHeight;
  1185.                pDibInfo->bmiHeader.biWidth     = IconWidth;
  1186.  
  1187.                SetDIBitsToDevice(hDC,
  1188.                        2, 2,
  1189.                        IconWidth, IconHeight,
  1190.                        0, 0,
  1191.                        0, IconHeight,
  1192.                        icon, (LPBITMAPINFO)pDibInfo,
  1193.                        DIB_PAL_COLORS);
  1194.  
  1195.                pDibInfo->bmiHeader.biSizeImage = tSize;
  1196.                pDibInfo->bmiHeader.biHeight    = tHeight;
  1197.                pDibInfo->bmiHeader.biWidth     = tWidth;
  1198.  
  1199.                GlobalUnlock(hIconBitmap);
  1200.  
  1201.                EndPaint(hWnd, &ps);
  1202.                break;
  1203.             }
  1204.             screen_to_be_cleared = 0;
  1205.             GetUpdateRect(hWnd, &tempRect, FALSE);
  1206.             PaintMathTools();
  1207.             hDC = BeginPaint(hWnd,&ps);
  1208.             if (last_written_y >= 0) {
  1209.               int top, bottom, left, right, xcount, ycount;
  1210.               /* bit-blit the invalidated bitmap area */
  1211.               int fromleft, fromtop, fromright, frombottom;
  1212.               long firstpixel;
  1213.               top    = tempRect.top;
  1214.               bottom = tempRect.bottom;
  1215.               left   = tempRect.left;
  1216.               right  = tempRect.right;
  1217.               if (bottom >  ydots) bottom = ydots;
  1218.               if (right  >= xdots) right  = xdots-1;
  1219.               if (top    >  ydots) top    = ydots;
  1220.               if (left   >= xdots) left   = xdots;
  1221.               fromleft  = left  + win_xoffset;
  1222.               fromright = right + win_xoffset;
  1223.               fromtop    = top    + win_yoffset;
  1224.               frombottom = bottom + win_yoffset;
  1225.               xcount = fromright - fromleft + 1;
  1226.               ycount = frombottom - fromtop;
  1227.               firstpixel = win_ydots - frombottom;
  1228.               firstpixel = firstpixel * bytes_per_pixelline;
  1229.               if (left < xdots && top < ydots) {
  1230.                   SelectPalette (hDC, hPal, 0);
  1231.                   RealizePalette(hDC);
  1232.                   SetMapMode(hDC,MM_TEXT);
  1233.                   SetDIBitsToDevice(hDC,
  1234.                        left, top,
  1235.                        xcount, ycount,
  1236.                        fromleft, 0,
  1237.                        0, ydots,
  1238.                        (LPSTR)&pixels[firstpixel], (LPBITMAPINFO)pDibInfo,
  1239.                        DIB_PAL_COLORS);
  1240.                   }
  1241.               }
  1242.             ValidateRect(hWnd, &tempRect);
  1243.             EndPaint(hWnd,&ps);
  1244.             PaintMathTools();
  1245.             break;
  1246.  
  1247.         case WM_DESTROY:
  1248.             /* delete the handle to the logical palette if it has any
  1249.                color entries and quit. */
  1250.             if (pLogPal->palNumEntries)
  1251.             DeleteObject (hPal);
  1252.             time_to_quit = 1;
  1253.             time_to_cycle = 0;
  1254.             WinHelp(hWnd,szHelpFileName,HELP_QUIT,0L);
  1255.             if (win_systempaletteused)
  1256.                 win_stop_cycling();
  1257.             SaveParameters(hWnd);
  1258.             GlobalFree(hIconBitmap);
  1259.             PostQuitMessage(0);
  1260.             break;
  1261.  
  1262.         case WM_ACTIVATE:
  1263.             if (!wParam) {  /* app. is being de-activated */
  1264.                 if (win_systempaletteused)
  1265.                     win_stop_cycling();
  1266.                 break;
  1267.                 }
  1268.         case WM_QUERYNEWPALETTE:
  1269.             /* If palette realization causes a palette change,
  1270.              * we need to do a full redraw.
  1271.              */
  1272.              if (last_written_y >= 0) {
  1273.                  hDC = GetDC (hWnd);
  1274.                  SelectPalette (hDC, hPal, 0);
  1275.                  i = RealizePalette(hDC);
  1276.                  ReleaseDC (hWnd, hDC);
  1277.                  if (i) {
  1278.                      InvalidateRect (hWnd, (LPRECT) (NULL), 1);
  1279.                      return 1;
  1280.                      }
  1281.                  else
  1282.                      return FALSE;
  1283.                  }
  1284.              else
  1285.                  return FALSE;
  1286.  
  1287.         case WM_PALETTECHANGED:
  1288.             if (wParam != hWnd){
  1289.                 if (last_written_y >= 0) {
  1290.                     hDC = GetDC (hWnd);
  1291.                     SelectPalette (hDC, hPal, 0);
  1292.                     i = RealizePalette (hDC);
  1293.                     if (i)
  1294.                         UpdateColors (hDC);
  1295.                     else
  1296.                         InvalidateRect (hWnd, (LPRECT) (NULL), 1);
  1297.                     ReleaseDC (hWnd, hDC);
  1298.                     }
  1299.                 }
  1300.             break;
  1301.  
  1302.         default:
  1303.             return (DefWindowProc(hWnd, message, wParam, lParam));
  1304.     }
  1305.     return (NULL);
  1306. }
  1307.  
  1308. win_oktocycle()
  1309. {
  1310. if (!(iRasterCaps) || iNumColors < 16) {
  1311.     stopmsg(0,
  1312.         "I'm sorry, but color-cycling \nrequires a palette-based\nvideo driver."
  1313.          );
  1314.     return(0);
  1315.     }
  1316. return(1);
  1317. }
  1318.  
  1319. extern int win_animate_flag;
  1320.  
  1321. win_stop_cycling()
  1322. {
  1323. HDC hDC;                      /* handle to device context           */
  1324.  
  1325. hDC = GetDC(GetFocus());
  1326. SetSystemPaletteUse(hDC,SYSPAL_STATIC);
  1327. ReleaseDC(GetFocus(),hDC);
  1328.  
  1329. time_to_cycle = 0;
  1330. win_animate_flag = 0;
  1331. restoredac();
  1332. win_systempaletteused = FALSE;
  1333. SetSysColors(COLOR_ENDCOLORS,(LPINT)win_syscolorindex,(LONG FAR *)win_syscolorold);
  1334. return(0);
  1335. }
  1336.  
  1337. void mono_dib_palette()
  1338. {
  1339. int i;        /* fill in the palette index values */
  1340.     for (i = 0; i < 128; i = i+2) {
  1341.         pDibInfo->bmiColors[i  ].rgbBlue      =   0;
  1342.         pDibInfo->bmiColors[i  ].rgbGreen     =   0;
  1343.         pDibInfo->bmiColors[i  ].rgbRed       =   0;
  1344.         pDibInfo->bmiColors[i  ].rgbReserved  =   0;
  1345.         pDibInfo->bmiColors[i+1].rgbBlue      = 255;
  1346.         pDibInfo->bmiColors[i+1].rgbGreen     = 255;
  1347.         pDibInfo->bmiColors[i+1].rgbRed       = 255;
  1348.         pDibInfo->bmiColors[i+1].rgbReserved  =   0;
  1349.         }
  1350. }
  1351.  
  1352. default_dib_palette()
  1353. {
  1354. int i, k;        /* fill in the palette index values */
  1355. int far *palette_values;    /* pointer to palette values */
  1356.  
  1357.     palette_values = (int far *)&pDibInfo->bmiColors[0];
  1358.     k = 0;
  1359.     for (i = 0; i < 256; i++) {
  1360.         palette_values[i] = k;
  1361.         if (++k >= iNumColors)
  1362.            if (iNumColors > 0)
  1363.                k = 0;
  1364.         }
  1365.     return(0);
  1366. }
  1367.  
  1368. rgb_dib_palette()
  1369. {
  1370. int i;        /* fill in the palette index values */
  1371.  
  1372.     for (i = 0; i < 256; i++) {
  1373.         pDibInfo->bmiColors[i].rgbRed       = dacbox[i][0] << 2;
  1374.         pDibInfo->bmiColors[i].rgbGreen     = dacbox[i][1] << 2;
  1375.         pDibInfo->bmiColors[i].rgbBlue      = dacbox[i][2] << 2;
  1376.         pDibInfo->bmiColors[i].rgbReserved  =   0;
  1377.         }
  1378.     return(0);
  1379. }
  1380.  
  1381.  
  1382. /****************************************************************************
  1383.  
  1384.    FUNCTION:   MakeHelpPathName
  1385.  
  1386.    PURPOSE:    Winfract assumes that the .HLP help file is in the same
  1387.                directory as the Winfract executable.This function derives
  1388.                the full path name of the help file from the path of the
  1389.                executable.
  1390.  
  1391. ****************************************************************************/
  1392.  
  1393. void MakeHelpPathName(szFileName)
  1394. char * szFileName;
  1395. {
  1396.    char *  pcFileName;
  1397.    int     nFileNameLen;
  1398.  
  1399.    nFileNameLen = GetModuleFileName(hInst,szFileName,EXE_NAME_MAX_SIZE);
  1400.    pcFileName = szFileName + nFileNameLen;
  1401.  
  1402.    while (pcFileName > szFileName) {
  1403.        if (*pcFileName == '\\' || *pcFileName == ':') {
  1404.            *(++pcFileName) = '\0';
  1405.            break;
  1406.        }
  1407.    nFileNameLen--;
  1408.    pcFileName--;
  1409.    }
  1410.  
  1411.    if ((nFileNameLen+13) < EXE_NAME_MAX_SIZE) {
  1412.        lstrcat(szFileName, "winfract.hlp");
  1413.    }
  1414.  
  1415.    else {
  1416.        lstrcat(szFileName, "?");
  1417.    }
  1418.  
  1419.    return;
  1420. }
  1421.  
  1422. set_win_offset()
  1423. {
  1424. win_xoffset = ((long)xposition*((long)xdots-(long)xpagesize))/100L;
  1425. win_yoffset = ((long)yposition*((long)ydots-(long)ypagesize))/100L;
  1426. if (win_xoffset+xpagesize > xdots) win_xoffset = xdots-xpagesize;
  1427. if (win_yoffset+ypagesize > ydots) win_yoffset = ydots-ypagesize;
  1428. if (xpagesize >= xdots) win_xoffset = 0;
  1429. if (ypagesize >= ydots) win_yoffset = 0;
  1430. return(0);
  1431. }
  1432.  
  1433.  
  1434.  
  1435. /*
  1436.   Read a formula file, picking off the formula names.
  1437.   Formulas use the format "  name = { ... }  name = { ... } "
  1438. */
  1439.  
  1440. int get_formula_names()     /* get the fractal formula names */
  1441. {
  1442.    int numformulas, i;
  1443.    FILE *File;
  1444.    char msg[81], tempstring[201];
  1445.  
  1446.    FormName[0] = 0;        /* start by declaring failure */
  1447.    for (i = 0; i < MaxFormNameChoices; i++) {
  1448.       FormNameChoices[i][0] = 0;
  1449.       win_choices[i] = FormNameChoices[i];
  1450.       }
  1451.  
  1452.    if((File = fopen(FormFileName, "rt")) == NULL) {
  1453.       sprintf("I Can't find %s", FormFileName);
  1454.       stopmsg(1,msg);
  1455.       return(-1);
  1456.    }
  1457.  
  1458.    numformulas = 0;
  1459.    while(fscanf(File, " %20[^ \n\t({]", FormNameChoices[numformulas]) != EOF) {
  1460.       int c;
  1461.  
  1462.       while(c = getc(File)) {
  1463.      if(c == EOF || c == '{' || c == '\n')
  1464.         break;
  1465.       }
  1466.       if(c == EOF)
  1467.      break;
  1468.       else if(c != '\n'){
  1469.      numformulas++;
  1470.      if (numformulas >= MaxFormNameChoices) break;
  1471. skipcomments:
  1472.      if(fscanf(File, "%200[^}]", tempstring) == EOF) break;
  1473.      if (getc(File) != '}') goto skipcomments;
  1474.      if (stricmp(FormNameChoices[numformulas-1],"") == 0 ||
  1475.          stricmp(FormNameChoices[numformulas-1],"comment") == 0)
  1476.          numformulas--;
  1477.       }
  1478.    }
  1479.    fclose(File);
  1480.    win_numchoices = numformulas;
  1481.    qsort(FormNameChoices,win_numchoices,21,
  1482.          (int(*)(const void*, const void *))strcmp);
  1483.    return(0);
  1484. }
  1485.  
  1486. int parse_formula_names()     /* parse a fractal formula name */
  1487. {
  1488.  
  1489.    strcpy(FormName, win_choices[win_choicemade]);
  1490.  
  1491.    if (RunForm(FormName)) {
  1492.        FormName[0] = 0;     /* declare failure */
  1493.        stopmsg(0,"Can't Parse that Formula");
  1494.        return(0);
  1495.        }
  1496.  
  1497. return(1);
  1498. }
  1499.  
  1500. /* --------------------------------------------------------------------- */
  1501.  
  1502. get_lsys_name()        /* get the Lsystem formula name */
  1503. {
  1504.    int numformulas, i;
  1505.    FILE *File;
  1506.    char buf[201];
  1507.  
  1508.    for (i = 0; i < MaxFormNameChoices; i++) {
  1509.       FormNameChoices[i][0] = 0;
  1510.       win_choices[i] = FormNameChoices[i];
  1511.       }
  1512.  
  1513.    if ((File = fopen(LFileName, "rt")) == NULL) {
  1514.       sprintf(buf,"I Can't find %s", LFileName);
  1515.       stopmsg(1,buf);
  1516.       LName[0] = 0;
  1517.       return(-1);
  1518.       }
  1519.  
  1520.    numformulas = 0;
  1521.    while (1) {
  1522.       int c;
  1523.       FormNameChoices[numformulas][0] = 0;
  1524.       if (fscanf(File, " %20[^ \n\t({]", FormNameChoices[numformulas]) == EOF)
  1525.      break;
  1526.       while(c = getc(File)) {
  1527.      if(c == EOF || c == '{' || c == '\n')
  1528.         break;
  1529.      }
  1530.       if(c == EOF)
  1531.      break;
  1532.       else if(c != '\n') {
  1533. skipcomments:
  1534.      if(fscanf(File, "%200[^}]", buf) == EOF) break;
  1535.      if (getc(File) != '}') goto skipcomments;
  1536.      if (stricmp(FormNameChoices[numformulas],"") != 0 &&
  1537.          stricmp(FormNameChoices[numformulas],"comment") != 0)
  1538.          if (++numformulas >= MaxFormNameChoices) break;
  1539.      }
  1540.       }
  1541.    fclose(File);
  1542.  
  1543.    win_numchoices = numformulas;
  1544.    qsort(FormNameChoices,win_numchoices,21,
  1545.          (int(*)(const void *, const void *))strcmp);
  1546.    return(0);
  1547. }
  1548.  
  1549. cant_clip()
  1550. {
  1551. MessageBox (
  1552.    GetFocus(),
  1553.    "Not Enough Free Memory to Copy to the Clipboard",
  1554.    "Fractint For Windows",
  1555.     MB_ICONSTOP | MB_OK);
  1556.     return(TRUE);
  1557. }
  1558.